package com.origin.grid.framework.controller;

import com.origin.grid.framework.common.vo.ResultMessage;
import com.origin.grid.framework.modules.verification.VerificationService;
import com.origin.grid.framework.modules.verification.entity.enums.VerificationEnums;
import com.origin.grid.framework.utils.ResultUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@Tag(name = "获取验证码接口")
@RequestMapping("/common")
@Slf4j
public class VerificationController {

    @Resource
    private VerificationService verificationService;

    @GetMapping("/common/slider/{verificationEnums}")
    @Operation(summary = "获取校验接口,一分钟同一个ip请求10次")
    public ResultMessage<Map<String, Object>> getSliderImage(@RequestHeader String uuid, @PathVariable VerificationEnums verificationEnums) {
        return ResultUtil.data(verificationService.createVerification(verificationEnums, uuid));
    }

    @PostMapping("/common/slider/{verificationEnums}")
    @Operation(summary = "验证码预校验")
    public ResultMessage verificationImage(Integer xPos, @RequestHeader String uuid, @PathVariable VerificationEnums verificationEnums) {
        boolean isPreCheck=verificationService.preCheck(xPos, uuid, verificationEnums);
        log.info("验证码预校验 {}",isPreCheck);
        return ResultUtil.data(isPreCheck);
    }
}
